package struct
{
	public class CycleList
	{
		private var currentNode:Node;
		
		private var head:Node;

		public function current():Object{
			return 	currentNode.content;
		}
		
		public function add(content:Object):void{
			if(content == null) return;
			var node:Node = new Node(content);
			if(head == null){
				currentNode = head = node;
				currentNode.next = currentNode;
				currentNode.pre = currentNode;
			}else{
				node.next = currentNode.next;
				node.next.pre = node;
				currentNode.next = node;
				node.pre = currentNode;
			}
		}
		
		public function remove(content:Object):void{
			var t:Node = head;
			do{
				if(t.content == content){
					removeNode(t);								
				}
				t = t.next;
			}while(t == head)
		}
		
		private function removeNode(node:Node):void{
			node.pre.next = node.next;
			node.next.pre = node.pre;
			node.next = null;
			node.pre = null;
		}

		public function next():Object{
			currentNode = currentNode.next;
			return currentNode.content;
		}
		
		public function pre():Object{
   			currentNode = currentNode.pre;
			return currentNode.content;
		}

	}
}